package com.hdd.art.filter.aop;


import com.alibaba.fastjson.JSON;
import com.hdd.art.utils.ThreadUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


/**
 * @author 刘章
 * @Title: HttpEventLogAspect.java
 * @Package com.zt.core.filter.aop
 * @Description: TODO(添加描述)
 * @date 2020年11月25日 下午3:23:56
 */
@Aspect
@Component
@Order (-100)
public class HttpEventLogAspect
{
	private static final Logger            log = LoggerFactory.getLogger(HttpEventLogAspect.class);
	

	private String                         client_id;
	

	private String                         client_project;
	

	private String                         client_project_name;
	


	@Pointcut ("execution(* com.hdd.art.test.*.*(..)) || execution(* com.hdd.art.test.*.*(..))")
	public void doEventLog() {
		
	}
	
	@Around ("doEventLog()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		long startTime = System.currentTimeMillis();
		Object[] args = point.getArgs();
		Object retVal = point.proceed(args);
		long endTime = System.currentTimeMillis();
		
//		UserOptLog userOptLog = new UserOptLog(client_id, client_project, client_project_name, request, point, retVal);
//		userOptLog.setTime(startTime);
//		userOptLog.setUsed_time(endTime - startTime);
//
//		log.debug("日志:" + JSON.toJSONString(userOptLog));
		
		//异步提交到kafka(kafka没起来的话，这里会影响接口效率)
//		ThreadUtil.pool.execute(new Runnable()
//		{
//
//			@Override
//			public void run() {
//				try {
//					//kafkaUserOptLogProviderService.sendMessage(userOptLog);
//					log.error("异步 提交日志:" );
//				}
//				catch (Exception e)
//				{
//					log.error("提交到kafka异常:" );
//				}
//
//			}
//		});
		return retVal;
	}
	
}
